#!/bin/bash
set -e
set -u
#
# This systemtest tests the plugin functionality
# of the Susan FD by using the supplied module
#   susan-fd-local-fileset.py
#
# The module will backup some files.
# This plugin is not intended for production,
# but is only a minimal example that shows
# how to use the python plugin interface.
# File attributes like uses and times will not be saved.
#
TestName="$(basename "$(pwd)")"
export TestName
bucket_name=susan-test

JobName=backup-susan-fd
#shellcheck source=../environment.in
. ./environment

testdata_opts=( \
  --address  "$SYSTEMTEST_LDAP_ADDRESS" \
  --basedn   "$SYSTEMTEST_LDAP_BASEDN" \
  --binddn   "$SYSTEMTEST_LDAP_BINDDN" \
  --password "$SYSTEMTEST_LDAP_PASSWORD"
)

tar xzf ../../data/image.tgz
./testdata.py "${testdata_opts[@]}" \
  --clean \
  --populate \
  --dump-backup > backup-data-before.ldif

JobName=backup-susan-fd
#shellcheck source=../scripts/functions
. "${rscripts}"/functions
"${rscripts}"/cleanup
"${rscripts}"/setup


start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
label volume=TestVolume001 storage=File pool=Full
run job=$JobName yes
status director
status client
status storage=File
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
wait
restore client=susan-fd fileset=PluginTest regexwhere=!ou=backup!ou=restore! select all done
yes
wait
messages
quit
END_OF_DATA

run_susan "$@"

check_for_zombie_jobs storage=File
stop_susan

check_two_logs

./testdata.py "${testdata_opts[@]}" \
  --dump-backup > backup-data-after.ldif
./testdata.py "${testdata_opts[@]}" \
  --dump-restore > restored-data.ldif

diff -u backup-data-before.ldif backup-data-after.ldif
diff -u backup-data-before.ldif restored-data.ldif

end_test
